<template>
	<view class="content fofa">
		<tabnav title="设置邮箱地址" :col="back"></tabnav>
		<view style="height: 90rpx;"></view>
		<view class="textCen">
			<image src="https://www.sign.run/applet/static/wode/yxImage.png" style="width: 141rpx;height: 117rpx;"></image>
		</view>
		<view class="textCen foSi35" style="margin-top: 53rpx;">设置邮箱地址</view>
		<view class="wid80 mar " style="margin-top: 65rpx;">
			<view class="foSi30" style="">邮箱地址</view>
			<input class="wid100 hei80 mar-top10" v-model="mailbox" placeholder="请输入邮箱地址"/>
			<view class="wid100 xia"></view>
			<!-- <view class="foSi30 mar-top30" style="">验证码</view>
			<view class="dis disAl hei80 disJuB mar-top10">
				<input style="width: 60%;" class="hei80" v-model="verificationCode" placeholder="请输入邮箱验证码"/>
				<view class="foSi35" :style="'color: '+back+';'" @click="yanzhengClick">{{codemsg}}</view>
			</view> -->
			<view class="wid100 xia"></view>
		</view>
		<view class="wid80 mar dis disAl disJuC coFFF foSi35 borRad10" :style="'background-color: '+back+';'"
		 style="margin-top: 71rpx;height: 91rpx;" @click="submit_to">提交</view>
	</view>
</template>

<script>
	import tabnav from "../../common/tabnav/tabnav.vue"
	export default {
		components: {
			tabnav,
		},
		data() {
			return {
				codenum: 0,
				codemsg: '获取验证码',
				mailbox: '',
				verificationCode: '',
				back: uni.getStorageSync('back'),
			}
		},
		onLoad() {
			
		},
		methods: {
			submit_to(){
				var that = this
				let email_reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
				
				if (!email_reg.test(that.mailbox)) {
					return uni.showToast({
						title:'邮箱格式错误',
						icon:'error'
					})
				}
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					url: that.global.url+'api/qianyu_dzq/applet_user_up_email',
					method: 'POST',
					header:{'site-id':that.global.site_id,'token':uni.getStorageSync('inuse_userinfo_token')},
					data: {
						email:that.mailbox
					},
					success(res) {
					    let result = res.data
						if(result.code == 1){
							uni.showToast({
								title:result.msg,
								icon:'success'
							})
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						}else{
							uni.showToast({
								title:result.msg,
								icon:'error'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				});
			},
			yanzhengClick(){
				if (this.codenum > 0) {
					return false;
				} else {
					this.codenum = 60
					let timer = setInterval(() => {
						this.codenum--;
						this.codemsg = this.codenum+'秒后获取'
						if (this.codenum < 1) {
							clearInterval(timer);
							this.codenum = 0
							this.codemsg = '重新获取'
						}
					}, 1000)
				}
			}
		}
	}
</script>

<style>
	.content {}
	.xia{
		height: 1rpx;
		background: #BFBFBF;
	}
</style>
